<?php
/**
 * 好大一个更新啊
 * @author xnny
 * @version 1.0
 */

set_time_limit(0);
define('IN_WT', true);
include 'include.php';
include 'config.php';

$db = mysqlDB::con();
$sql = 'SELECT `BID` , `Blog_Feed` FROM blog_info WHERE `Blog_State` =1 ORDER BY RAND() LIMIT 0 , 1';
$blogInfo = $db->getRow($sql);
$BID = empty($blogInfo['BID']) ? wt_log::writeLog($sql . "\n", 'upEr') : $blogInfo['BID'];
$feed = empty($blogInfo['Blog_Feed']) ? wt_log::writeLog($sql . "\n", 'upEr') : $blogInfo['Blog_Feed'];

#获得源的文章列表
$xmls = new wt_xml($feed);
$RSS = $xmls->getRSS();

$i = 0;
if (!empty($RSS['post']))
{
	$newPost = array_reverse($RSS['post']);
	foreach ($newPost as $v)
	{
		if (empty($v['postPubDate']))
		{
			$pid = wt_post::postLink2pid($v['postLink']);
		}
		else
		{
			$pid = true;
			$v['postPubDate'] = wt_post::strtotimeExtend($v['postPubDate']);
		}
		#$v['postPubDate'] = empty($v['postPubDate']) ? time() : strtotime($v['postPubDate']);
		if (wt_post::getLastUpdate($feed) < $v['postPubDate'] || !$pid)
		{
			$i ++;
			echo '.';
			wt_post::addPost($v, $BID);
		}
		if ($i > 0)
		{
			echo 'ds';
			wt_post::clearCache($BID);
			wt_post::creatCache($BID);
		}
	}
}
